# -*- coding:utf-8 -*-
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2.QtCore import *
from ..cgai import CGAI
from .CGAIPalette import CGAIBasePalatte
from .CGAIBaseWidget import CGAIEdit


class EditWidget(QLineEdit):

    def __init__(self):
        super(EditWidget, self).__init__()

        self.setFixedHeight(20)
        self.setFont(QFont("",CGAI.EDIT_FONT_SIZE,35))
        p=self.palette()
        p.setColor(QPalette.Base,QColor('#1C1C1C'))
        p.setColor(QPalette.Text,QColor('#E8E8E8'))

        self.setStyleSheet('''
        QLineEdit{border: 0px}
        QLineEdit{background: #1C1C1C}
        ''')
        self.setPalette(p)


class EditInput(QWidget):
    """
    双击节点弹出更名输入
    """
    edit_Signal = Signal(str)
    def __init__(self):
        super(EditInput, self).__init__()
        self.setHidden(True)
        self.setStyleSheet('QWidget{background-color:rgb(75,75,75);color:rgb(200,200,200)}')
        self.setWindowFlags(Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint)
        self.main_layout = QHBoxLayout()
        self.edit = EditWidget()
        self.main_layout.addWidget(self.edit)
        self.setLayout(self.main_layout)




    def keyPressEvent(self,QKeyEvent):
        if QKeyEvent.key() in [Qt.Key_Return,Qt.Key_Escape,Qt.Key_Enter]:
            text = self.edit.text()
            self.edit_Signal.emit(text)
            print(text)
            self.setHidden(True)
            self.edit.clear()